Skip to content

[perf] [runtime] Optimize startup by using function pointers instead of delegates for our native->managed bridge. - #16702

Merged
rolfbjarne merged 4 commits into
dotnet:mainfrom
rolfbjarne:perf-improve-startup
Nov 18, 2022
Merged

[perf] [runtime] Optimize startup by using function pointers instead of delegates for our native->managed bridge.#16702
rolfbjarne merged 4 commits into
dotnet:mainfrom
rolfbjarne:perf-improve-startup

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Nov 10, 2022

Copy link
Copy Markdown
Member

Use function pointers to our managed callbacks instead of delegates for the native->managed bridge. This makes execution faster on AOT (because the AOT compiler can just emit the native function address, no need to go through the expensive marshalling machinery).

This involved a few changes to make the managed callbacks only use blittable types in the function signature:

  • Use sbyte / int8_t instead of bool.
  • Use pointers instead of out/ref arguments.
  • Use IntPtr instead of string arguments.

The code rarely shows up in timing profiles before the change, and never after. This means that time-wise this doesn't save all that much, because there wasn't much to gain to begin with (but it's still a gain).

Memory-wise, we're now allocation 0,19 MiB less on startup (17,61 MiB vs 17,42 MiB).

…of delegates for our native->managed bridge.
@rolfbjarne rolfbjarne added the performance If an issue or pull request is related to performance label Nov 10, 2022
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

❗ API diff for current PR / commit (Breaking changes)

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)

❗ API diff vs stable (Breaking changes)

Legacy Xamarin (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 113db5e15b8a97d228a0d44e1360ff860014c75c [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1162.Monterey'
Hash: 113db5e15b8a97d228a0d44e1360ff860014c75c [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • introspection
  • monotouch-test

Pipeline on Agent
Hash: 113db5e15b8a97d228a0d44e1360ff860014c75c [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 223 tests passed 🎉

Tests counts

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 23 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: [PR build]

@rolfbjarne rolfbjarne changed the title [DRAFT] [perf] [runtime] Optimize startup by using function pointers instead of delegates for our native->managed bridge. [perf] [runtime] Optimize startup by using function pointers instead of delegates for our native->managed bridge. Nov 14, 2022
@rolfbjarne
rolfbjarne marked this pull request as ready for review November 14, 2022 16:31
@rolfbjarne
rolfbjarne merged commit ae0d5b5 into dotnet:main Nov 18, 2022
@rolfbjarne
rolfbjarne deleted the perf-improve-startup branch November 18, 2022 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance If an issue or pull request is related to performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants